import { ReduceAction, State } from '../interfaces/redux'
import * as types from './types'

export default function reducer(
  state: State = { n: 1 },
  { type, payload }: ReduceAction
): State {
  switch (type) {
    case types.INCREASE:
      return { ...state, n: state.n + payload }
      break
    case types.DECREASE:
      return { ...state, n: state.n - payload }
      break
  }
  return state
}
